package com.sicheng.datastruct.linkedlist;

import java.util.Objects;

@SuppressWarnings("unused")
public class CircleSingleLinkedNode<T>{
    private final Node<T> head = new Node<>();


    public void insertOnTail(Node<T> insert){
        Node<T> current=head;
        while (current.next !=head ) {
            current = current.next;
        }
        current.next=insert;
        insert.next=head;
    }
    public void display(){
        Node<T> current =head;
        while (current.next!=head){
            System.out.println(current.next);
            current=current.next;
        }
    }


}
class Node<T>{
    public T data;
    public Node<T> next=this;
    public Node(T data) {
        this.data = data;
    }

    public Node() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Node<?> node = (Node<?>) o;
        return Objects.equals(data, node.data);
    }

    @Override
    public int hashCode() {
        return Objects.hash(data);
    }

    @Override
    public String toString() {
        return "Node{" +
                "data=" + data +
                '}';
    }
}
